<?
require_once("../config/dbconn.php");require_once("../config/powercls.php");


$curday=date('Y-m-d',$curtime);
//获取系统的第一个会员
$sql_hy="select * from {$db_prefix}users where gluser=''";
$rs_hy=$db->get_one($sql_hy);
$curusername=$rs_hy["username"];

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	
}
td{
	font-size:12px;
}
-->
</style>
<script language="javascript" type="text/javascript" src="../calendar/WdatePicker.js"></script>
<link href="images/skin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="17" height="29" valign="top" background="images/mail_leftbg.gif"><img src="images/left-top-right.gif" width="17" height="29" /></td>
    <td width="935" height="29" valign="top" background="images/content-bg.gif"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
      <tr>
        <td height="31"><div class="titlebt">管理网体</div></td>
      </tr>
    </table></td>
    <td width="16" valign="top" background="images/mail_rightbg.gif"><img src="images/nav-right-bg.gif" width="16" height="29" /></td>
  </tr>
  <tr>
    <td height="71" valign="middle" background="images/mail_leftbg.gif">&nbsp;</td>
    <td valign="top" bgcolor="#F7F8F9"><table width="100%" height="138" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td valign="top">
		<table width="75%" align="center" cellspacing="1">
    <?
		foreach($hyrankary as $k1=>$v1){
           $glo_mostmin =  "glo_mostmin_".$k1;
           $glo_mostmax =  "glo_mostmax_".$k1;
	?>
	  <TD width="60" height="25" align="right" valign="middle" bgColor="<?php echo $hycolorary[$k1];?>"><font color="#FFFFFF"><? if($k1!=6){echo $v1.":".$$glo_mostmin."~".$$glo_mostmax;}else{echo $v1.":".$$glo_mostmin."以上";}?></font></TD>
	  <?
	  }
	  ?>
	  </table>	
	  <form action="" method="get" name="form1" id="form1">
	  <table width="100%" border="0">
		<tr>
		<td height="30" align="center">
		  <input type="hidden" name="action" value="query">
		  <span id="Label1"> 用户名：</span>
		  <input name="username" type="text" id="username" size="10">
				  <input type="submit" name="bgt" value="搜索"></td>
		</tr>
	</table>
	</form>
		
		<?
		if ($action=='query'){
			if (trim($username)!=''){
				$sqlhy="select username from {$db_prefix}users where username='".trim($username)."'";
				$rshy=$db->get_one($sqlhy);
				if ($rshy) $curusername=$rshy["username"];
				else die("没有此会员");
			}
		}
		?>
		<table align="center">
          <tr>
            <td><!-- 拓扑图开始 -->
  <?php
if ($curusername){
	$sql11="select * from {$db_prefix}users where username='".$curusername."'";
	
	$rs11=$db->get_one($sql11);
	if (!$rs11) die("没有此会员");
?>
                <?
		if ($rs11["gluser"]){
		?>
                <br>
                  <div align="center">
                    <input type="button" name="bt1" value="上一层" id="bt1" onClick="location.href='?username=<? echo urlencode($rs11["gluser"])?>&action=query&periods=<?=$periods?>';">
                    <input type="button" name="bt2" value="置顶" id="bt2" onClick="location.href='?username=<? echo urlencode($rs_hy["username"])?>&action=query&periods=<?=$periods?>';">
                  </div>
                <br>
                  <?
}
?>
            </td></tr>
          <tr>
            <td><table align="center" cellpadding="0" cellspacing="0" width="100%">
              <tr>
                  <td valign="top" align="center"><table width="198" border="0" cellspacing="1" cellpadding="0" bgcolor="silver">
                    <tr>
                      <td colspan="4" align="center" bgcolor="<?php echo $hycolorary[$rs11['rank']];?>"><a style="WIDTH: 100px; BACKGROUND-COLOR:<? echo $hycolorary[$rs11['rank']];?>" href="?username=<? echo urlencode($rs11["username"])?>&action=query"><font color="ffffff"><strong><? echo $rs11["username"]?></strong></font></a></td>
                    </tr>
                    <tr>
                      <td height="20" colspan="4" align="center" bgcolor="#ffffff"><? echo $hyrankary[$rs11["rank"]]?></td>
                    </tr>
                    <tr>
                      <td colspan="4" align="center" bgcolor="#ffffff"><?php  echo $rs11['nickname'];?></td>
                    </tr>
					   <tr>  <td width="96" align="center" bgcolor="#ffffff">
					   <?
                    $gl_left = $db->get_one("select id,username from {$db_prefix}users where gluser='".$rs11['username']."' and pos =1");
                        if(!empty($gl_left)){
                          $left_id = $gl_left['id'];
                          $left_username = $gl_left['username'];
                          //左区业绩
                          $left_yeji = $db->get_one("select sum(price+sfprice) as priceall from {$db_prefix}users where FIND_IN_SET({$left_id},glstr)or id={$left_id}");
                        if(!empty($left_yeji)){
                            $leftall_yeji = $left_yeji['priceall'];
                            echo $leftall_yeji;
                        }
                    }else{
                      echo 0;
                    }
                    ?>
					   </td>
					     <td width="96" align="center" bgcolor="#ffffff"> <?
                    $gl_right = $db->get_one("select id,username from {$db_prefix}users where gluser='".$rs11['username']."' and pos =2");
                    if(!empty($gl_right)){
                $right_id = $gl_right['id'];
                $right_username = $gl_right['username'];
                //右区业绩
                $right_yeji = $db->get_one("select sum(price+sfprice) as priceall from {$db_prefix}users where FIND_IN_SET({$right_id},glstr)or id={$right_id}");
                if(!empty($right_yeji)){
                    $rightall_yeji = $right_yeji['priceall'];
                    echo $rightall_yeji;
                }
            }else{
              echo 0;
            }
                    ?></td>
					     
					   </tr>
                    <tr>
                      <td colspan="4" align="center" ><? echo date("Y-m-d",$rs11["regtime"])?></td>
                    </tr>
                    <tr> </tr>
                  </table></td>
              </tr>
              </table>
                <table border="0" align="center" cellspacing="0" cellpadding="0">
                  <tr>
                    <td align="center"><img style="WIDTH: 1px; HEIGHT: 20px" alt="" src="images/line.gif" border="0" /></td>
                  </tr>
                </table>
              <?php

//冒泡求解
function glnettree($gl_username,$dtp,$dtp1,$gldepth1){
global $db,$db_prefix,$hyrankary,$hycolorary,$action,$time,$beginday,$endday,$periods;
if ($dtp>=$dtp1){
?>
                <table align="center" cellpadding="0" cellspacing="0">
                  <tr>
    <?php
		$sql="select posnum from {$db_prefix}users where username='$gl_username' ";
		$res=$db->get_one($sql);
		$i=1;
		$c_num=2;//$res["posnum"];
		for($m=1;$m<=$c_num;$m++){
		$sql="select * from {$db_prefix}users where gluser='$gl_username' and pos='$m' ";
		$rs=$db->get_one($sql);
	?>
                    <td align="center" valign="top"><? if ($c_num>1){ ?>
                        <?
	if (($i==1) && ($c_num>$i)){
	?>
                        <table border="0" cellspacing="0" cellpadding="0" width="100%">
                          <tr>
                            <td align="center"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                  <td width="50%" height="1" ></td>
                                  <td width="50%" height="1" bgcolor="silver"></td>
                                </tr>
                              </table>
                                <img style="WIDTH: 1px; HEIGHT: 20px" alt="" src="images/line.gif" border="0" /></td>
                          </tr>
                        </table>
                      <?
	}else if(($i>1) && ($c_num==$i)){
	?>
                        <table border="0" cellspacing="0" cellpadding="0" width="100%">
                          <tr>
                            <td align="center"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                  <td width="50%" height="1" bgcolor="silver"></td>
                                  <td width="50%" height="1" ></td>
                                </tr>
                              </table>
                                <img style="WIDTH: 1px; HEIGHT: 20px" alt="" src="images/line.gif" border="0" /></td>
                          </tr>
                        </table>
                      <?
	}else{
	?>
                        <table border="0" cellspacing="0" cellpadding="0" width="100%">
                          <tr>
                            <td align="center"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                  <td width="50%" height="1" bgcolor="silver"></td>
                                  <td width="50%" height="1" bgcolor="silver"></td>
                                </tr>
                              </table>
                                <img src="images/line.gif" alt="" width="27" border="0" style="WIDTH: 1px; HEIGHT: 20px" /></td>
                          </tr>
                        </table>
                      <?
	}
	}
	?>
                        <!---->
                        <?php  if(!empty($rs)){	  ?>
                        <table width="200" border="0" cellspacing="1" cellpadding="0" bgcolor="silver">
                          <tr>
                            <td width="195" colspan="4" align="center" bgcolor="<?php echo $hycolorary[$rs['rank']];?>"><a style="WIDTH: 100px; BACKGROUND-COLOR: <? echo $hycolorary[$rs['rank']]?>" href="?username=<? echo urlencode($rs["username"])?>&action=query"><font color="ffffff"><strong><? echo $rs["username"]?></strong></font></a></td>
                          </tr>
                          <tr>
                            <td height="20" colspan="4" align="center" bgcolor="#ffffff"><? echo $hyrankary[$rs['rank']]?>（
                              <?=$rs['gldepth']-$gldepth1?>

                            层）</td>
                          </tr>
                          <tr>
                            <td colspan="4" align="center"  bgcolor="#ffffff"><?php  echo $rs['nickname'];?></td>
                          </tr>
						  <tr>
                            <td align="center" bgcolor="#ffffff"> <?
                    $gl_left = $db->get_one("select id,username from {$db_prefix}users where gluser='".$rs['username']."' and pos =1");
                        if(!empty($gl_left)){
                          $left_id = $gl_left['id'];
                          $left_username = $gl_left['username'];
                          //左区业绩
                          $left_yeji = $db->get_one("select sum(price+sfprice) as priceall from {$db_prefix}users where FIND_IN_SET({$left_id},glstr)or id={$left_id}");
                        if(!empty($left_yeji)){
                            $leftall_yeji = $left_yeji['priceall'];
                            echo $leftall_yeji;
                        }
                    }else{
                      echo 0;
                    }
                    ?>
                            </td>
						    <td align="center" bgcolor="#ffffff"> <?
                    $gl_right = $db->get_one("select id,username from {$db_prefix}users where gluser='".$rs['username']."' and pos =2");
                    if(!empty($gl_right)){
                $right_id = $gl_right['id'];
                $right_username = $gl_right['username'];
                //右区业绩
                $right_yeji = $db->get_one("select sum(price+sfprice) as priceall from {$db_prefix}users where FIND_IN_SET({$right_id},glstr)or id={$right_id}");
                if(!empty($right_yeji)){
                    $rightall_yeji = $right_yeji['priceall'];
                    echo $rightall_yeji;
                }
            }else{
              echo 0;
            }
                    ?></td>
						   
					      </tr>
                          <tr>
                            <td colspan="4" align="center" ><? echo date("Y-m-d",$rs["regtime"])?></td>
                          </tr>
                        </table>
                        <?php }else{ ?>
                        <table border="0" cellpadding="0" cellspacing="1" bgcolor="silver" align="center" style="margin:0px 10px;">
                          <tr>
                            <td align="center"  width="70" bgcolor="#FFFFFF"><a href="user_reg.php?gluser=<?php echo $gl_username;?>&pos=<?php echo $i;?>&regfrom=net">注册</font></a> </td>
                          </tr>
                        </table>
                      <?php	} ?>
                        <?
	$sql1="select *  from {$db_prefix}users where username='".$rs["username"]."' ";
	$rs1=$db->get_one($sql1);
	?>
                        <div style="display:" id="table_<? echo $rs["id"]?>">
                          <?	if (!empty($rs1)&&$dtp1<$dtp){ ?>
                          <table align="center" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td align="center"><img style="WIDTH: 1px; HEIGHT: 20px" alt="" src="images/line.gif" border="0" /></td>
                            </tr>
                          </table>
                          <?php
	glnettree($rs["username"],$dtp,$dtp1+1,$gldepth1);
     }
    ?>
                      </div></td>
                    <?php
	$i++;
     }
?>
                  </tr>
                </table>
              <?php } }
	//查看拓扑图
	glnettree($rs11["username"],3,1,$rs11['gldepth']);
}
?>
            </td>
          </tr>
        </table></td>
      </tr>
      
    </table></td>
    <td background="images/mail_rightbg.gif">&nbsp;</td>
  </tr>
  <tr>
    <td valign="middle" background="images/mail_leftbg.gif"><img src="images/buttom_left2.gif" width="17" height="17" /></td>
      <td height="17" valign="top" background="images/buttom_bgs.gif"><img src="images/buttom_bgs.gif" width="17" height="17" /></td>
    <td background="images/mail_rightbg.gif"><img src="images/buttom_right2.gif" width="16" height="17" /></td>
  </tr>
</table>

</body>
</html>
